﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Utils;

public partial class Themn_2_Default : PowerCreator.LMS.Web.Base.WebBasePage
{
    PowerCreator.LMS.ViewQuery.ViewQuery opViewQuery = new PowerCreator.LMS.ViewQuery.ViewQuery();
    PowerCreator.LMS.Web.Course.Resource opResource = new PowerCreator.LMS.Web.Course.Resource();
    PowerCreator.LMS.Web.Channel.Channel opChannel = new PowerCreator.LMS.Web.Channel.Channel();
    protected PowerCreator.LMS.Web.Config.WebConfig config = new PowerCreator.LMS.Web.Config.WebConfig();
    protected string HtmlLastUploadResource = "";
    protected string HtmlPublicCourse = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = config.GetLanagerValueByKey("WebTitle", PowerCreator.LMS.Language.LanagetItemType.WebTitle); //"PowerCreator 学习管理系统";
        if (!IsPostBack)
        {
            //BinderChannel();
            //HtmlLastUploadResource=BinderNewResource();
            //HtmlPublicCourse=BinderCourse();
        }
    }

    protected override void InitPage()
    {
        base.InitPage();
    }
    //private void BinderChannel()
    //{

    //    if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
    //    {
    //        //td_Channel.Visible = false;
    //        return;
    //    }
    //    //直播频道
    //    string ActiveClassIds = opChannel.GetActiveClassIDs();
    //    string search = "status > 0 and ChannelName not like '%_Student'  and ID not in (" + ActiveClassIds + ")";
    //    DataTable dt = opChannel.QueryChannel(search);
    //    //if(dt.Rows.Count==0)
    //    //    td_Channel.Visible = false;
    //    dt.Columns.Add("IsShuang");   //双视频,0不是，1是
    //    dt.Columns.Add("ChannelUrl");
    //    for (int i = 0; i < dt.Rows.Count; i++)
    //    {
    //        dt.Rows[i]["IsShuang"] = "0";
    //        string search1 = string.Format("status > 0 and ChannelName like '{0}_Student'", dt.Rows[i]["ChannelName"]);
    //        DataTable dt1 = opChannel.QueryChannel(search1);
    //        if (dt1.Rows.Count >= 1)
    //        {
    //            dt.Rows[i]["IsShuang"] = "1";
    //        }

    //        int i_Flag = int.Parse(dt.Rows[i]["status"].ToString());
    //        int u_LOWORD = PowerCreator.LMS.Web.Channel.ChannelUtils.LOWORD(i_Flag);
    //        int u_HIWORD = PowerCreator.LMS.Web.Channel.ChannelUtils.HIWORD(i_Flag);

    //        if (PowerCreator.LMS.Web.Config.WebConfig.IsUseWeGe)
    //        {
    //            if (u_LOWORD != 2)
    //            {
    //                if (u_HIWORD != 2)
    //                {
    //                    dt.Rows[i].Delete();
    //                }
    //                else
    //                {
    //                    dt.Rows[i]["ChannelUrl"] = "ChannelCommetNew.aspx?urltype=leftup&ContentID=" + dt.Rows[i]["ContentID"].ToString() + "&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&type=Vedio&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();

    //                }
    //            }
    //            else
    //            {
    //                if (u_HIWORD != 2)
    //                {
    //                    dt.Rows[i]["ChannelUrl"] = "ChannelCommetNew.aspx?urltype=right&ContentID=" + dt.Rows[i]["ContentID"].ToString() + "&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
    //                }
    //                else
    //                {
    //                    dt.Rows[i]["ChannelUrl"] = "ChannelCommetNew.aspx?urltype=all&ContentID=" + dt.Rows[i]["ContentID"].ToString() + "&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
    //                }
    //            }

    //            if (dt.Rows[i]["IsShuang"].ToString() == "1")
    //                dt.Rows[i]["ChannelUrl"] ="ChannelCommetNew.aspx?urltype=dual&ContentID=" + dt.Rows[i]["ContentID"].ToString() + "&ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
    //        }
    //        else
    //        {
    //            if (u_LOWORD != 2)
    //            {
    //                if (u_HIWORD != 2)
    //                {
    //                    dt.Rows[i].Delete();
    //                }
    //                else
    //                {
    //                    dt.Rows[i]["ChannelUrl"] = WebUtils.WebRoot + "/web/broadcast/frmleftup.aspx?ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&type=Vedio" + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();

    //                }
    //            }
    //            else
    //            {
    //                if (u_HIWORD != 2)
    //                {
    //                    dt.Rows[i]["ChannelUrl"] = WebUtils.WebRoot + "/web/broadcast/frm000.aspx?ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
    //                }
    //                else
    //                {
    //                    dt.Rows[i]["ChannelUrl"] = WebUtils.WebRoot + "/web/broadcast/Content.aspx?ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ChannelName=" + dt.Rows[i]["ChannelName"].ToString() + "&Title=" + dt.Rows[i]["Title"].ToString() + "&Author=" + dt.Rows[i]["Author"].ToString() + "&Description=" + dt.Rows[i]["Description"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();
    //                }
    //            }

    //            if (dt.Rows[i]["IsShuang"].ToString() == "1")
    //                dt.Rows[i]["ChannelUrl"] = WebUtils.WebRoot + "/web/broadcast/dual/content.aspx?ChannelID=" + dt.Rows[i]["ID"].ToString() + "&ServerIP=" + dt.Rows[i]["ServerIP"].ToString();

    //        }
    //    }
    //    rpt_Channel.DataSource = dt;
    //    rpt_Channel.DataBind();
    //}

    //private string BinderNewResource()
    //{
    //    string Html="";
    //    string CoursersResourceImageUrl = "";
    //    //最新上传
    //    string search = " ResourseState=1 ";
    //    string orderBy = "ResourceCreatedTime desc";
    //    DataTable dt = opResource.QueryResource(search, orderBy, 4, 1);
    //    string CourseResourceID = "0";
    //    if(dt.Rows.Count==0)
    //        Html="<tr><td></td></tr>";
    //    else
    //    {
    //        int iResult = 0;
    //        int m = 0;
    //        for (int i = 0; i < dt.Rows.Count; i++)
    //        {
    //            CoursersResourceImageUrl = GetPath(dt.Rows[i]["ResourceUrl"].ToString(), int.Parse(dt.Rows[i]["ResourceClass"].ToString())) + GetPicName(dt.Rows[i]["ResourceEntry"].ToString(), int.Parse(dt.Rows[i]["ResourceClass"].ToString()));
    //            CourseResourceID = GetCourseResourseID(dt.Rows[i]["ResourceID"].ToString());
    //            int k = Math.DivRem(i, 4, out iResult);
    //            if (iResult == 0)
    //                Html += "<tr>";
    //            Html += " <td>";
    //            Html += "<div class=\"center2ct\">";
    //            Html += "<table class=\"jct\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"94%\" align=\"center\">";
    //            Html += "<tr>";
    //            Html += "<td ><a href=\"CoursewareDescription.aspx?ResourceID=" + dt.Rows[i]["ResourceID"].ToString() + "\" target=_blank><img alt=\"" + dt.Rows[i]["ResourceName"].ToString() + "\" src=\"" + CoursersResourceImageUrl + "\"  width=\"117\" height=\"87\"   style=\"border: 1px solid #99CCFF;\" /></a></td>";
    //            Html += "</tr>";
    //            Html += "<tr>";
    //            Html += "<td >";
    //            Html += "<span class=\"bt1\">";
    //            Html += "<p> <a href=\"CoursewareDescription.aspx?ResourceID=" + dt.Rows[i]["ResourceID"].ToString() + "\" title=\"" + dt.Rows[i]["ResourceName"].ToString() + "\" target=_blank>" + PowerCreator.LMS.Common.Utils.StringUtils.GetSubstringLue(dt.Rows[i]["ResourceName"].ToString(), 7) + "</a></p>";
    //            Html += " </span>";
    //            Html += "</td>";
    //            Html += "</tr>";
    //            Html += " <tr>";
    //            Html += "<td valign=\"top\">";
    //            Html += "<p>" + config.GetLanagerValueByKey("lbl_AddCourseInfo_TeacherName", PowerCreator.LMS.Language.LanagetItemType.Page) + "：" + dt.Rows[i]["ResourceAuthor"].ToString() + "</p>";
    //            Html += " <p >" + config.GetLanagerValueByKey("lbl_AddResourceInfo_VideoTime", PowerCreator.LMS.Language.LanagetItemType.Page) + "：" + Math.DivRem(int.Parse(dt.Rows[i]["ResourceVideoTime"].ToString()), 60, out m) + config.GetLanagerValueByKey("Msg_AddPaperInfo_minute", PowerCreator.LMS.Language.LanagetItemType.Page) + "</p>";
    //            Html += " <p>" + config.GetLanagerValueByKey("web_bbs_titlelist_gv_c3", PowerCreator.LMS.Language.LanagetItemType.Page) + "：" + dt.Rows[i]["ResourceClickNum"].ToString() + "</p>";
    //            Html += "</td>";
    //            Html += "</tr>";
    //            Html += "</table>";
    //            Html += "</td>";
    //            if (iResult == 3)
    //                Html += "</tr>";

    //        }
    //        for (int j = 3 - iResult; j > 0; j--)
    //        {

    //            Html += " <td>";
    //            Html += "<div class=\"center2ct\">";
    //            Html += "</td>";
    //            if (iResult == 0)
    //                Html += "</tr>";
    //        }
    //   }
    //    return Html;
    //}
    //private string GetCourseResourseID(string ResourceID)
    //{
    //    string ID = "0";
    //    string search = "select top 1 CourseresID from TCourseResource where FKCoursersResourceID="+ResourceID;
    //    PowerCreator.LMS.ViewQuery.ViewQuery ov=new PowerCreator.LMS.ViewQuery.ViewQuery();
    //    DataTable dt = ov.Query(search);
    //    if (dt.Rows.Count == 1)
    //        ID = dt.Rows[0][0].ToString();
    //    return ID;
    //}
    //private string BinderCourse()
    //{
    //    string Html = "";
    //    //公开课程
    //    PowerCreator.LMS.Web.Course.Course opCourse = new PowerCreator.LMS.Web.Course.Course();
    //    string search = "CourseIsCompulsory = 3 and CourseState = 1";
    //    string orderList = "CourseCreatetime desc,CourseId desc";
    //    DataTable dt = opCourse.QueryCourse(search, orderList, 4, 1);

    //    if (dt.Rows.Count == 0)
    //        Html = "<tr><td></td></tr>";
    //    else
    //    {
    //        int iResult = 0;
    //        int m = 0;
    //        for (int i = 0; i < dt.Rows.Count; i++)
    //        {
    //            int k = Math.DivRem(i,4, out iResult);
    //            if (iResult == 0)
    //                Html += "<tr>";
    //            Html += " <td><div class=\"center2ct\">";
    //            Html += "<table class=\"jct\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"94%\" align=\"center\">";
    //            Html += "<tr>";
    //            Html += "<td height=\"30\"><a href=\"OpenCourse.aspx?CourseID=" + dt.Rows[i]["CourseID"].ToString() + "&ProjectID=0\"><img alt=\"" + dt.Rows[i]["CourseName"].ToString() + "\" src=\"" + dt.Rows[i]["CourseImgUrl"].ToString() + "\" width=\"117\" height=\"87\" style=\"border: 1px solid #99CCFF\" /></a></td>";
    //            Html += "</tr>";
    //            Html += "<tr>";
    //            Html += "<td ><span class=\"bt2\">";
    //            Html += " <p> <a href=\"OpenCourse.aspx?CourseID=" + dt.Rows[i]["CourseID"].ToString() + "&ProjectID=0\" title=\"" + dt.Rows[i]["CourseName"].ToString() + "\">" + PowerCreator.LMS.Common.Utils.StringUtils.GetSubstringLue(dt.Rows[i]["CourseName"].ToString(), 7) + "</a></p>";
    //            Html += "</span> </td>";
    //            Html += "</tr>";
    //            Html += "<tr>";
    //            Html += "<td valign=\"top\"><p>" + config.GetLanagerValueByKey("lbl_AddCourseInfo_TeacherName", PowerCreator.LMS.Language.LanagetItemType.Page) + "：" + PowerCreator.LMS.Common.Utils.StringUtils.GetSubstringLue(dt.Rows[i]["CourseMostlyTeacherName"].ToString(),4) + "</p>";
    //            Html += "<p> " + config.GetLanagerValueByKey("lbl_AddCourseInfo_CoursePeriod", PowerCreator.LMS.Language.LanagetItemType.Page) + "：" + dt.Rows[i]["CoursePeriod"].ToString() + " </p>";
    //            //Html += "<p>  " + config.GetLanagerValueByKey("lbl_CourseResource_CourseType", PowerCreator.LMS.Language.LanagetItemType.Page) + "：" + dt.Rows[i]["CoursePeriod"].ToString() + "</p></td>";
    //            Html += "</tr>";
    //            Html += "</table>";
    //            Html += " </div></td>";
    //            if (iResult == 3)
    //                Html += "</tr>";

    //        }
    //        for (int j = 3 - iResult; j > 0; j--)
    //        {

    //            Html += " <td>";
    //            Html += "<div class=\"center2ct\">";
    //            Html += "</td>";
    //            if (iResult == 0)
    //                Html += "</tr>";
    //        }
    //    }
    //    return Html;

    //}

    


    //private string GetPicName(string fileName, int Resourceclass)
    //{
    //    string rt = "images/gkkpic.jpg";
    //    if (Resourceclass == 1)
    //    {
    //        rt = "000.jpg";
    //    }
    //    else if (Resourceclass == 2)
    //    {
    //        string[] fileNames = fileName.Split('.');
    //        if (fileNames.Length == 2)
    //            rt = fileNames[0].ToString() + ".jpg";
    //    }
    //    return rt;
    //}
    //private string GetPath(string Path, int Resourceclass)
    //{
    //    string rt = Path;
    //    if (Resourceclass != 1 && Resourceclass != 2)
    //    {
    //        rt = "";
    //    }
    //    return rt;
    //}


}
